package com.wildwolf.project.wildwolf.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wildwolf.project.wildwolf.R;
import com.wildwolf.project.wildwolf.adapter.ContactListAdapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

public class WildwolfMessageActivity extends FragmentActivity {
/**
 * messsage类型
 */
	private final List<MessageTypeHolder> messageList = new ArrayList<MessageTypeHolder>();
	 private final Map<String, ContactListAdapter> contactListAdapters = new HashMap<String, ContactListAdapter>();
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.layout_message);
}

/**
 * PagerAdapter for the contact list.
 */
private class MessageListPagerAdapter extends FragmentPagerAdapter {

/**
 * Create a {@link ListPagerAdapter}.
 * @param fm the {@link FragmentManager}
 * @param viewPager the {@link ViewPager} associate with this adapter
 */
public MessageListPagerAdapter(final FragmentManager fm, final ViewPager viewPager) {
    super(fm);
    viewPager.setAdapter(this);
}

@Override
public Fragment getItem(int position) {
    String messageType = messageList.get(position).messageType;
    ContactListFragment f = ContactListFragment.newInstance(messageType);
    f.setListAdapter(getContactListAdapter(messageType));
    return f;
}

@Override
public int getCount() {
    return 0;
}

ContactListAdapter getContactListAdapter(String group) {return null;
}

}
private static class MessageTypeHolder {
/**
 * 消息类别
 */
	String messageType;
	/**
	 * 是否是首要的
	 */
	boolean isPrincipal;

	/**
	 * Create a {@link GroupHolder}.
	 * @param group the group name
	 */
	public MessageTypeHolder(final String messageType) {
	    this.messageType = messageType;
	}

	/**
	 * Create a list of GroupHolder.
	 * @param groups list of group name
	 * @return a list of {@link GroupHolder}
	 */
	public static List<MessageTypeHolder> createFrom(List<String> messageTypes) {
	    List<WildwolfMessageActivity.MessageTypeHolder> result = new ArrayList<WildwolfMessageActivity.MessageTypeHolder>();
	    for (String messageType : messageTypes) {
		result.add(new WildwolfMessageActivity.MessageTypeHolder(messageType));
	    }
	    return result;
	}

	/**
	 * 是否已经存在一个消息类型在现有的列表中
	 * @param messageTypes
	 * @param messageType
	 * @return
	 */
	public static boolean contains(List<WildwolfMessageActivity.MessageTypeHolder> messageTypes, String messageType) {
	    for (WildwolfMessageActivity.MessageTypeHolder groupHolder : messageTypes) {
		if (groupHolder.messageType.equals(messageType))
		    return true;
	    }
	    return false;
	}

/**
 * 设定唯一一个显示的
 * @param messageTypes
 * @param position
 */
	public static void setUniquePrincipal(List<WildwolfMessageActivity.MessageTypeHolder> messageTypes, int position) {
	    for (WildwolfMessageActivity.MessageTypeHolder messageType : messageTypes) {
	    	messageType.isPrincipal = false;
	    }
	    messageTypes.get(position).isPrincipal = true;
	}
  }
}
